package example.json;
import java.io.File;
import java.io.FileInputStream;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

public class JSONExample {
    public static void main(String[] args) {
        String content = null;
        try {
            final File jsonFile = new File("res/org_json/qq.txt");
            final FileInputStream fis = new FileInputStream(jsonFile);
            final byte[] buf = new byte[fis.available()];
            fis.read(buf);

            content = new String(buf, "UTF8");
        } catch (final Exception e) {
            e.printStackTrace();
        }

        if (content != null) {
            try {
                final JSONObject obj = ((JSONObject) new JSONTokener(content).nextValue()).getJSONObject("data");
                final JSONArray array = obj.getJSONArray("info");

                for (int i = 0, len = array.length(); i < len; i++) {
                    System.out.println("origtext: " + array.getJSONObject(i).getString("origtext"));
                }
            } catch (final JSONException e) {
                e.printStackTrace();
            }
        }
    }

}
